﻿

using HBase;
using hconnect;
using System;
using System.Collections.Generic;

namespace hCommand
{
    public abstract class SingleTaskAllocateJobTask<T> : SuperiorAllocateJobTask where T : BaseTask
    {

        List<T> getWorking() {
            List<T> tList = MyCache.query((T a) => a.status < 80 && a.status > 11 && getSuperiorIndex() == a.driveId);
            return tList;   
        }
        public override sealed List<BaseTask> analyseTaskModel(AbsStatus gcs)
        {

            List<T> tList = getWorking();
            if (!canSendNew(tList)) {
                return null;
            }
            BaseTask ct = continueSingleTaskModel(gcs, tList);
            if (ct != null)
            {
                return new List<BaseTask> { ct };
            }
            

            BaseTask bt = analyseSingleTaskModel(gcs);
            if (bt == null)
            {
                return null;
            }
            return new List<BaseTask> { bt };


        }

        public virtual bool canSendNew(List<T> tList)
        {
            if (tList.Count == 0)
            {
                return true;
            }
            else
            {
                console(InfoCode.consleOnly_Sinple_more, tList[0].taskNo + "任务执行中"+ tList[0].status);
                return false;

            }
        }

        public abstract BaseTask analyseSingleTaskModel(AbsStatus gcs);
        public override int getBegin(BaseTask bt)
        {


            return 0;
        }

        public virtual BaseTask continueSingleTaskModel(AbsStatus gcs, List<T> tList) { 
            foreach(T t in tList) {
                if (t.canWork() && t.status == (int)CoreTaskParamStatus.取货完成) {
                    return t;
                } else {
                    return null;
                }
            
            }
            return null;
        }
        

    }
}
